package com.laiketui.admin.mch.plugin;

import com.laiketui.admin.mch.api.plugin.BargainService;
import com.laiketui.domain.vo.MainVo;
import com.laiketui.domain.vo.plugin.bargin.AddBargainGoodsVo;
import com.laiketui.root.annotation.HttpApiMethod;
import com.laiketui.core.domain.Result;
import com.laiketui.core.exception.LaiKeAPIException;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 砍价后台管理
 *
 * @author Trick
 * @date 2021/5/13 15:11
 */
@Api(tags = "砍价后台管理")
@RestController
@RequestMapping("/pc/bargain")
public class BargainController {

    @Autowired
    private BargainService bargainService;

    @ApiOperation("砍价后台管理")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "goodsName", value = "活动标题", dataType = "string", paramType = "form"),
            @ApiImplicitParam(name = "status", value = "活动状态", dataType = "int", paramType = "form"),
            @ApiImplicitParam(name = "id", value = "砍价活动商品id", dataType = "int", paramType = "form")
    })
    @PostMapping("/index")
    @HttpApiMethod(urlMapping = "pc.admin.bargain.index")
    public Result index(MainVo vo, String goodsName, Integer status, Integer id) throws LaiKeAPIException {
        try {
            return Result.success(bargainService.index(vo, goodsName, status, id));
        } catch (LaiKeAPIException e) {
            return Result.error(e.getCode(), e.getMessage());
        }
    }


    @ApiOperation("置顶")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "砍价活动商品id", dataType = "int", paramType = "form")
    })
    @PostMapping("/top")
    @HttpApiMethod(urlMapping = "pc.admin.bargain.top")
    public Result top(MainVo vo, int id) throws LaiKeAPIException {
        try {
            return Result.success(bargainService.top(vo, id));
        } catch (LaiKeAPIException e) {
            return Result.error(e.getCode(), e.getMessage());
        }
    }

    @ApiOperation("砍价活动明细")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "goodsId", value = "商品id", dataType = "int", paramType = "form")
    })
    @PostMapping("/bargainDetail")
    @HttpApiMethod(urlMapping = "pc.admin.bargain.bargainDetail")
    public Result bargainDetail(MainVo vo, int goodsId) throws LaiKeAPIException {
        try {
            return Result.success(bargainService.bargainDetail(vo, goodsId));
        } catch (LaiKeAPIException e) {
            return Result.error(e.getCode(), e.getMessage());
        }
    }

    @ApiOperation("删除砍价活动")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "ids", value = "商品id", dataType = "string", paramType = "form")
    })
    @PostMapping("/del")
    @HttpApiMethod(urlMapping = "pc.admin.bargain.del")
    public Result del(MainVo vo, String ids) throws LaiKeAPIException {
        try {
            return Result.success(bargainService.del(vo, ids));
        } catch (LaiKeAPIException e) {
            return Result.error(e.getCode(), e.getMessage());
        }
    }

    @ApiOperation("获取砍价记录")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "barginId", value = "砍价活动id", dataType = "int", paramType = "form"),
            @ApiImplicitParam(name = "userName", value = "用户名称", dataType = "int", paramType = "form"),
            @ApiImplicitParam(name = "type", value = "all- 全部 0-砍价中 1-砍价成功 2-砍价失败", dataType = "string", paramType = "form")
    })
    @PostMapping("/bargainRecordInfo")
    @HttpApiMethod(urlMapping = "pc.admin.bargain.bargainRecordInfo")
    public Result bargainRecordInfo(MainVo vo, Integer barginId, String userName, String type) throws LaiKeAPIException {
        try {
            return Result.success(bargainService.bargainRecordInfo(vo, barginId, userName, type));
        } catch (LaiKeAPIException e) {
            return Result.error(e.getCode(), e.getMessage());
        }
    }

    @ApiOperation("帮砍详情")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "barginId", value = "砍价活动id", dataType = "int", paramType = "form"),
            @ApiImplicitParam(name = "userName", value = "用户名称", dataType = "int", paramType = "form"),
            @ApiImplicitParam(name = "type", value = "all- 全部 0-砍价中 1-砍价成功 2-砍价失败", dataType = "string", paramType = "form")
    })
    @PostMapping("/bargainHelperInfo")
    @HttpApiMethod(urlMapping = "pc.admin.bargain.bargainHelperInfo")
    public Result bargainHelperInfo(MainVo vo, String orderNo) throws LaiKeAPIException {
        try {
            return Result.success(bargainService.bargainHelperInfo(vo, orderNo));
        } catch (LaiKeAPIException e) {
            return Result.error(e.getCode(), e.getMessage());
        }
    }

    @ApiOperation("获取砍价商品列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "classId", value = "商品类型id", dataType = "int", paramType = "form"),
            @ApiImplicitParam(name = "brandId", value = "品牌id", dataType = "int", paramType = "form"),
            @ApiImplicitParam(name = "title", value = "商品名称", dataType = "int", paramType = "form")
    })
    @PostMapping("/getBargainGoods")
    @HttpApiMethod(urlMapping = "pc.admin.bargain.getBargainGoods")
    public Result getBargainGoods(MainVo vo, Integer classId, Integer brandId, String title) throws LaiKeAPIException {
        try {
            return Result.success(bargainService.getBargainGoods(vo, classId, brandId, title));
        } catch (LaiKeAPIException e) {
            return Result.error(e.getCode(), e.getMessage());
        }
    }


    @ApiOperation("添加砍价商品活动")
    @PostMapping("/addBargainGoods")
    @HttpApiMethod(urlMapping = "pc.admin.bargain.addBargainGoods")
    public Result addBargainGoods(AddBargainGoodsVo vo) throws LaiKeAPIException {
        try {
            return Result.success(bargainService.addBargainGoods(vo));
        } catch (LaiKeAPIException e) {
            return Result.error(e.getCode(), e.getMessage());
        }
    }

}
